package com.movie.repository;

import com.movie.entity.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface CategoryRepository extends JpaRepository<Category, Long> {
    
    Optional<Category> findByName(String name);
    
    Optional<Category> findBySlug(String slug);
    
    List<Category> findByStatusTrue();
    
    List<Category> findByType(String type);
    
    List<Category> findByStatusTrueAndType(String type);
    
    @Query("SELECT COUNT(m) FROM Movie m WHERE m.category.id = :categoryId")
    Integer countMoviesByCategoryId(Long categoryId);
    
    boolean existsByName(String name);
    
    boolean existsBySlug(String slug);
    
    List<Category> findByNameContainingIgnoreCase(String name);
    
    List<Category> findByNameContainingIgnoreCaseAndType(String name, String type);
}